package com.ybkj.o2o.zhuanche.service.impl;

import com.ybkj.o2o.zhuanche.common.CompanyOrderVo;
import com.ybkj.o2o.zhuanche.common.DriverOrderDetailVo;
import com.ybkj.o2o.zhuanche.common.DriverOrderVo;
import com.ybkj.o2o.zhuanche.common.MemberOrderVo;
import com.ybkj.o2o.zhuanche.common.OrderFromSourceVo;
import com.ybkj.o2o.zhuanche.common.PageVo;
import com.ybkj.o2o.zhuanche.common.SerialNumber;
import com.ybkj.o2o.zhuanche.common.chart.HourChart;
import com.ybkj.o2o.zhuanche.common.query.OrderQuery;
import com.ybkj.o2o.zhuanche.entity.ChartDay;
import com.ybkj.o2o.zhuanche.entity.ChartMonth;
import com.ybkj.o2o.zhuanche.entity.ChartYear;
import com.ybkj.o2o.zhuanche.entity.Order;
import com.ybkj.o2o.zhuanche.entity.OrderCriteria;
import com.ybkj.o2o.zhuanche.entity.OrderCriteria.Criteria;
import com.ybkj.o2o.zhuanche.mapper.BaseMapper;
import com.ybkj.o2o.zhuanche.mapper.OrderMapper;
import com.ybkj.o2o.zhuanche.service.OrderService;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DefaultOrderService extends AbstractBaseService<Order, OrderCriteria, Long> implements
        OrderService {

  @Autowired
  private OrderMapper orderMapper;
  @Autowired
  private SerialNumber serialNumber;

  @Override
  public BaseMapper<Order, OrderCriteria, Long> getMapper() {
    return orderMapper;
  }

  @Override
  public int insert(Order order) {
    Assert.notNull(order.getAppkey());
    // 生产订单号
    //DateFormat format = new SimpleDateFormat("yyMMdd");
    //String date = format.format(new Date());
    order.setOrderNo("ZC" + serialNumber.getSeqNo());
    Date date2 = new Date();
    order.setCreated(date2);
    order.setUpdated(date2);
    order.setLasturge(date2);
    order.setStatus(0);
    order.setVersion(1L);
    order.setReview(Boolean.FALSE);
    order.setTreatment(Boolean.FALSE);
    return super.insert(order);
  }

  // 补单
  @Override
  public int addmore(Order order) {
    Assert.notNull(order.getAppkey());
    // 生产订单号
    order.setOrderNo("ZC" + serialNumber.getSeqNo());
    Date date2 = new Date();
    order.setCreated(date2);
    order.setUpdated(date2);
    order.setLasturge(date2);
    order.setStatus(2);
    order.setVersion(1L);
    order.setReview(Boolean.FALSE);
    order.setTreatment(Boolean.FALSE);
    return super.insert(order);
  }

  @Override
  public Order queryOneOrder(Long orderId, String appKey) {
    return orderMapper.selectOneOrder(orderId, appKey);
  }

  @Override
  public Order findByIdAndAppKey(Long orderId, String appKey) {
    return orderMapper.selectByIdAndAppKey(orderId, appKey);
  }

  @Override
  public Long countByParam(OrderQuery orderQuery) {
    return orderMapper.countByParams(orderQuery);
  }

  @Override
  public long countForToday(String appKey) {

    Assert.notNull(appKey);

    Calendar calendar = Calendar.getInstance();
    calendar = DateUtils.truncate(calendar, Calendar.DAY_OF_MONTH);

    Date day2 = DateUtils.addDays(calendar.getTime(), 1);

    OrderCriteria orderCriteria = new OrderCriteria();
    orderCriteria.createCriteria().andAppkeyEqualTo(appKey)
            .andCreatedGreaterThanOrEqualTo(calendar.getTime()).andCreatedLessThan(day2);

    return orderMapper.countByExample(orderCriteria);
  }

  @Override
  public List<Order> findByEmployId(OrderQuery orderQuery) {
    return orderMapper.selectByEmployId(orderQuery);
  }

  @Override
  public ChartYear dataForYear(Integer year, Long companyId, String appKey) {
    ChartYear chartYear = new ChartYear();
    BigDecimal total = new BigDecimal(0);
    OrderCriteria example = new OrderCriteria();
    Criteria criteria = example.createCriteria();
    long destroy = 0;
    long finish = 0;
    try {

      finish =
              orderMapper.finishOrderCount(DateUtils.parseDate(year + "-01-01", "yyyy-MM-dd"),
                      DateUtils.parseDate((year + 1) + "-01-01", "yyyy-MM-dd"), companyId, appKey);
      destroy =
              orderMapper.destroyOrderCount(DateUtils.parseDate(year + "-01-01", "yyyy-MM-dd"),
                      DateUtils.parseDate((year + 1) + "-01-01", "yyyy-MM-dd"), companyId, appKey);
      criteria
              .andAppkeyEqualTo(appKey)
              .andFinishTimeBetween(DateUtils.parseDate(year + "-01-01", "yyyy-MM-dd"),
                      DateUtils.parseDate(year + "-12-31", "yyyy-MM-dd")).andStatusEqualTo(5);
      if (companyId != null) {
        criteria.andCompanyIdEqualTo(companyId);
      }
      List<Order> list = orderMapper.selectByExample(example);
      if (CollectionUtils.isEmpty(list)) {
        for (Order order : list) {
          total = total.add(new BigDecimal(order.getRealPay() != null ? order.getRealPay() : 0));
        }
      }

    } catch (ParseException ex) {
      ex.printStackTrace();
    }


    chartYear.setTotalCancelNum(destroy);
    chartYear.setTotalSuccessNum(finish);
    chartYear.setTotalPrice(total);
    chartYear.setYear(year);
    List<ChartMonth> months = new ArrayList<ChartMonth>();
    for (int i = 0; i < 12; i++) {
      months.add(this.dataForMonth(year, i, companyId, appKey));
    }
    chartYear.setMonths(months);

    return chartYear;
  }

  @Override
  public ChartMonth dataForMonth(Integer year, Integer month, Long companyId, String appKey) {
    ChartMonth chartMonth = new ChartMonth();
    OrderCriteria example = new OrderCriteria();
    Criteria criteria = example.createCriteria();
    BigDecimal total = new BigDecimal(0);
    long finish = 0;
    long destroy = 0;
    String end = "";
    if (month == 12) {
      end = (year + 1) + "-01-01";
    } else {
      end = year + "-" + (month + 2 > 9 ? month + 2 : "0" + (month + 2)) + "-01";
    }

    try {
      finish = orderMapper.finishOrderCount(
                              
          DateUtils.parseDate(year + "-"
              + ((month + 1) > 9 ? (month + 1) : "0" + (month + 1)) + "-01", "yyyy-MM-dd"),
              
              DateUtils.parseDate(end, "yyyy-MM-dd"), companyId, appKey);
      destroy = orderMapper.destroyOrderCount(
                              
          DateUtils.parseDate(year + "-"
              + ((month + 1 > 9) ? (month + 1) : "0" + (month + 1)) + "-01", "yyyy-MM-dd"),
              
              DateUtils.parseDate(end, "yyyy-MM-dd"), companyId, appKey);
      criteria.andAppkeyEqualTo(appKey).andFinishTimeGreaterThanOrEqualTo(
          DateUtils.parseDate(year + "-" + ((month + 1) > 9 ? (month + 1) : "0" + (month + 1))
                              + "-01", "yyyy-MM-dd"))
              .andFinishTimeLessThan(DateUtils.parseDate(end, "yyyy-MM-dd"));
      criteria.andStatusEqualTo(5);
      if (companyId != null) {
        criteria.andCompanyIdEqualTo(companyId);
      }
      List<Order> list = orderMapper.selectByExample(example);
      for (Order order : list) {
        total = total.add(new BigDecimal(order.getRealPay() != null ? order.getRealPay() : 0));
      }
      chartMonth.setMonth(month);
      chartMonth.setTotalCancelNum(destroy);
      chartMonth.setTotalSuccessNum(finish);
      chartMonth.setTotalPrice(total);
    } catch (ParseException ex) {
      ex.printStackTrace();
    }

    return chartMonth;
  }

  @Override
  public ChartDay dataForChartDay(Integer year, Integer month, int day, Long companyId,
                                  String appKey) {
    ChartDay chartDay = new ChartDay();
    OrderCriteria example = new OrderCriteria();
    Criteria criteria = example.createCriteria();
    BigDecimal total = new BigDecimal(0);
    long finish = 0;
    long destroy = 0;
    String end = "";
    if ((month + 1) == 12 && day == 31) {
      end = (year + 1) + "-01" + "-01";
    } else if (day == 31) {
      end = year + "-" + (month + 2 > 9 ? month + 2 : "0" + (month + 2)) + "-01";
    } else {
      end =
              year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1)) + "-"
                      + ((day + 1) > 9 ? day + 1 : "0" + (day + 1));
    }


    try {
      finish = orderMapper.finishOrderCount(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day), "yyyy-MM-dd"),
              DateUtils.parseDate(end, "yyyy-MM-dd"), companyId, appKey);
      destroy = orderMapper.destroyOrderCount(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day), "yyyy-MM-dd"),
              DateUtils.parseDate(end, "yyyy-MM-dd"), companyId, appKey);
      criteria.andAppkeyEqualTo(appKey).andFinishTimeGreaterThanOrEqualTo(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day), "yyyy-MM-dd"))
              .andFinishTimeLessThan(DateUtils.parseDate(end, "yyyy-MM-dd"));
      criteria.andStatusEqualTo(5);
      if (companyId != null) {
        criteria.andCompanyIdEqualTo(companyId);
      }
      List<Order> list = orderMapper.selectByExample(example);
      if (CollectionUtils.isEmpty(list)) {
        for (Order order : list) {
          total = total.add(new BigDecimal(order.getRealPay() != null ? order.getRealPay() : 0));
        }
      }

    } catch (ParseException ex) {
      ex.printStackTrace();
    }


    chartDay.setDay(day);
    chartDay.setTotalCancelNum(destroy);
    chartDay.setTotalSuccessNum(finish);
    chartDay.setTotalPrice(total);
    return chartDay;
  }

  @Override
  public HourChart dataForhour(Integer year, Integer month, Integer day, int hour, Long companyId,
                               String appKey) {
    HourChart hourChart = new HourChart();
    OrderCriteria example = new OrderCriteria();
    Criteria criteria = example.createCriteria();
    BigDecimal total = new BigDecimal(0);
    long finish = 0;
    long destroy = 0;
    String end = "";
    if ((month + 1) == 12 && day == 31 && hour == 23) {
      end = (year + 1) + "-01" + "-01 00:00:00";
    } else if (day == 31 && hour == 23) {
      end = year + "-" + (month + 2 > 9 ? month + 2 : "0" + (month + 2)) + "-01 00:00:00";
    } else if (hour == 23) {
      end =
              year
                      + "-"
                      + ((month + 1 > 9 ? month + 1 : "0" + (month + 1)) + "-"
                      + ((day + 1) > 9 ? day + 1 : "0" + (day + 1)) + " 00:00:00");
    } else {
      end =
              year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1)) + "-"
                      + ((day) > 9 ? day : ("0" + (day))) + " "
                      + ((hour + 1 > 9 ? hour + 1 : hour + 1) + ":00:00");
    }

    try {
      finish = orderMapper.finishOrderCount(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day) + " " + (hour > 9 ? hour : ("0" + hour))
              + ":00:00", "yyyy-MM-dd HH:mm:ss"),
              DateUtils.parseDate(end, "yyyy-MM-dd HH:mm:ss"), companyId, appKey);
      destroy = orderMapper.destroyOrderCount(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day) + " " + (hour > 9 ? hour : ("0" + hour))
              + ":00:00", "yyyy-MM-dd HH:mm:ss"),
              DateUtils.parseDate(end, "yyyy-MM-dd HH:mm:ss"), companyId, appKey);
      criteria.andAppkeyEqualTo(appKey).andFinishTimeGreaterThanOrEqualTo(
          DateUtils.parseDate(year + "-" + (month + 1 > 9 ? month + 1 : "0" + (month + 1))
              + "-" + (day > 9 ? day : "0" + day) + " " + (hour > 9 ? hour : ("0" + hour))
              + ":00:00", "yyyy-MM-dd HH:mm:ss"))
              .andFinishTimeLessThan(DateUtils.parseDate(end, "yyyy-MM-dd HH:mm:ss"));
      criteria.andStatusEqualTo(5);
      if (companyId != null) {
        criteria.andCompanyIdEqualTo(companyId);
      }
      List<Order> list = orderMapper.selectByExample(example);
      if (CollectionUtils.isEmpty(list)) {
        for (Order order : list) {
          total = total.add(new BigDecimal(order.getRealPay() != null ? order.getRealPay() : 0));
        }
      }
      hourChart.setHour(hour);
      hourChart.setTotalCancel(destroy);
      hourChart.setTotalSuccess(finish);
      hourChart.setTotalPrice(total);
    } catch (ParseException ex) {
      ex.printStackTrace();
    }


    return hourChart;
  }

  @Override
  public PageVo<OrderFromSourceVo> orderFromSource(Date date1, Date date2, Long companyId,
                                                   String appKey) {
    PageVo<OrderFromSourceVo> orderFromSources = new PageVo<OrderFromSourceVo>();
    List<OrderFromSourceVo> orderFromSourceList = new ArrayList<OrderFromSourceVo>();
    BigDecimal amount = new BigDecimal(0);
    BigDecimal aggregateAmount = new BigDecimal(0);
    List<String> fromSource = orderMapper.queryAllFromSource(companyId, appKey);
    for (String str : fromSource) {
      Map<String, Object> map =
              orderMapper.findByFromSource(date1, date2, companyId, "%" + str + "%", appKey);
      OrderFromSourceVo sourceVo = new OrderFromSourceVo();
      sourceVo.setFromSource(str);
      sourceVo.setMoney(
          map == null ? new BigDecimal(0) : new BigDecimal((Double) map.get("money")));
      sourceVo.setAmount(map == null ? 0 : (long) map.get("count"));
      orderFromSourceList.add(sourceVo);
      amount = amount.add(map == null ? new BigDecimal(0) : new BigDecimal(map.get("count") + ""));
      aggregateAmount =
              aggregateAmount.add(map == null ? new BigDecimal(0) : new BigDecimal(map.get("money")
                      + ""));
    }

    orderFromSources.setTotal(amount);
    orderFromSources.setContent(orderFromSourceList);
    orderFromSources.setTotalElements(orderFromSourceList.size());
    orderFromSources.setAllTotal(aggregateAmount);

    return orderFromSources;
  }

  public List<Order> findHastenOrder(String appKey) {
    return orderMapper.findHastenOrder(appKey);
  }

  @Override
  public PageVo<DriverOrderVo> driverAchievement(Date date1, Date date2, Long empCompanyId,
                                                 String appKey) {
    List<DriverOrderVo> list =
            orderMapper.queryAllDriverAchievement(date1, date2, empCompanyId, appKey);
    PageVo<DriverOrderVo> vo = new PageVo<DriverOrderVo>();
    vo.setContent(list);
    return vo;
  }

  @Override
  public PageVo<CompanyOrderVo> companyOrder(Date date1, Date date2, String appKey) {
    PageVo<CompanyOrderVo> companyOrders = new PageVo<CompanyOrderVo>();
    List<CompanyOrderVo> finishList = new ArrayList<CompanyOrderVo>();
    List<CompanyOrderVo> cancelList = new ArrayList<CompanyOrderVo>();

    List<CompanyOrderVo> orders = new ArrayList<CompanyOrderVo>();
    List<String> companys = new ArrayList<String>();
    companys = orderMapper.queryAllCompany(appKey);
    finishList = orderMapper.companyOrders(date1, date2, appKey);
    cancelList = orderMapper.companyCancelNums(date1, date2, appKey);
    BigDecimal finishcount = new BigDecimal(0);
    BigDecimal cancelcount = new BigDecimal(0);
    BigDecimal money = new BigDecimal(0);
    for (String company : companys) {
      CompanyOrderVo vo = new CompanyOrderVo();
      vo.setCompanyName(company);
      vo.setFinishNums(0);
      vo.setCancelNums(0);

      for (CompanyOrderVo companyVo : finishList) {
        if (company.equals(companyVo.getCompanyName())) {
          vo.setFinishNums(companyVo.getFinishNums());
          vo.setMoney(companyVo.getMoney());
          break;
        }
      }
      for (CompanyOrderVo companyVo : cancelList) {
        if (company.equals(companyVo.getCompanyName())) {
          vo.setCancelNums(companyVo.getCancelNums());
          break;
        }
      }

      finishcount = finishcount.add(new BigDecimal(vo.getFinishNums()));
      cancelcount = cancelcount.add(new BigDecimal(vo.getCancelNums()));
      money = money.add(vo.getMoney());
      orders.add(vo);
    }
    companyOrders.setContent(orders);
    companyOrders.setAllTotal(finishcount);
    companyOrders.setSumMoney(money);
    companyOrders.setTotal(cancelcount);

    return companyOrders;
  }

  @Override
  public Order findByDriverAndFinishTime(Long employId, Date start, Date end, String appKey) {

    return orderMapper.selectFinishedByDriverWithDate(employId, start, end, null, null,appKey);

  }

  @Override
  public List<Order> findMonthOrder(Integer year, Integer month, String appKey) {
    Calendar calendar = Calendar.getInstance();

    Date start = null;
    Date end = null;

    if (null == year) {
      year = calendar.get(Calendar.YEAR);
    }
    if (null == month) {
      month = calendar.get(Calendar.MONTH);
    }
    try {
      start =
              DateUtils.parseDate(year + "-" + (month > 9 ? month : ("0" + month)) + "-01",
                      "yyyy-MM-dd");// 2015-01-01
      if (month != 12) {
        end =
                DateUtils.parseDate(year + "-" + ((month + 1) > 9 ? (month + 1) : "0" + (month + 1))
                        + "-01", "yyyy-MM-dd");
      } else {
        end = DateUtils.parseDate((year + 1) + "-" + "01" + "-01", "yyyy-MM-dd");// 2015-01-01
      }
    } catch (ParseException ex) {
      ex.printStackTrace();
    }
    return orderMapper.selectMonthOrder(start, end,appKey);
  }

  @Override
  public PageVo<MemberOrderVo> findMemberOrder(Date startTime, Date endTime, Long companyId,
                                               String appKey) {
    List<MemberOrderVo> list = orderMapper.selectMemberOrder(startTime, endTime, companyId, appKey);
    PageVo<MemberOrderVo> pageVo = new PageVo<MemberOrderVo>();
    pageVo.setContent(list);
    pageVo.setTotalElements(list.size());

    return pageVo;
  }

  @Override
  public PageVo<DriverOrderDetailVo> driverOrderDetailVo(
      Long driverId, Date start, Date end, Integer page, Integer rows, String appKey) {
    OrderCriteria example = new OrderCriteria();
    Criteria criteria = example.createCriteria();
    if (driverId != null) {
      criteria.andEmployIdEqualTo(driverId);
    }
    if (start != null) {
      criteria.andFinishTimeGreaterThanOrEqualTo(start);
    }
    if (end != null) {
      criteria.andFinishTimeLessThanOrEqualTo(end);
    }
    criteria.andAppkeyEqualTo(appKey);
    criteria.andStatusEqualTo(5);
    Long count = orderMapper.countByExample(example);
    Integer offset = 0;
    if (null != page && null != rows) {
      offset = (page - 1) * rows;
    }
    List<DriverOrderDetailVo> list =
            orderMapper.queryDetailByDriverId(driverId, start, end, offset, rows, appKey);
    PageVo<DriverOrderDetailVo> pageVo = new PageVo<DriverOrderDetailVo>();
    pageVo.setContent(list);
    pageVo.setTotalElements(count);
    return pageVo;
  }


  @Override
  public Long queryRunOrder(OrderQuery orderQuery) {
    Long count = 0L;
    try {
      count = orderMapper.countByParams(orderQuery);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return count;
  }

  @Override
  public List<Order> findMyFinishOrder(OrderQuery orderQuery) {
    return orderMapper.selectByParams(orderQuery);
  }


  @Override
  public Long countRunningOrder(Long carTypeId, String appKey) {
    Long total = 0L;
    total = orderMapper.countRunningOrder(carTypeId, appKey);
    return total;
  }

  @Override
  public List<Order> findByParams(OrderQuery orderQuery) {
    return orderMapper.selectByParams(orderQuery);
  }
  
  @Override
  public List<Order> findByParamsInBook(OrderQuery orderQuery) {
    return orderMapper.selectByParamsInBook(orderQuery);
  }
  
  @Override
  public Long countByParamsInBook(OrderQuery orderQuery) {
    return orderMapper.countByParamsInBook(orderQuery);
  }
  
  @Override
  public List<Order> queryByParams(OrderQuery orderQuery) {
    return orderMapper.selectOrders(orderQuery);
  }

  @Override
  public Long countByParams(OrderQuery orderQuery) {
    return orderMapper.countByParams(orderQuery);
  }

  @Override
  public List<Order> exportOrders(OrderQuery orderQuery) {
    return orderMapper.exportOrders(orderQuery);
  }

  @Override
  public List<Order> queryFinishOrder(OrderQuery orderQuery) {
    return orderMapper.selectFinishOrder(orderQuery);
  }
  
  @Override
  public List<Order> selectFinishOrder(OrderQuery orderQuery) {
    return orderMapper.selectFinishOrderByEmploy(orderQuery);
  }

  @Override
  public Long countFinishOrder(OrderQuery orderQuery) {
    return orderMapper.countFinishOrder(orderQuery);
  }
  @Override
  public Long countFinishOrderByEmploy(OrderQuery orderQuery) {
    return orderMapper.countFinishOrderByEmploy(orderQuery);
  }
  
  @Transactional(rollbackFor = Exception.class)
  public int prepare(Long orderId,String appKey) {
    Order order = orderMapper.selectPrepare(orderId,appKey);
    return orderMapper.updateFinishTime(order.getId(),appKey);
  }

  @Override
  public Map<String, Object> countFinishByCompay(
      Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countFinishByCompay(companyId,startTime,endTime,appKey);
  }

  @Override
  public Long countRunByCompany(Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countRunByCompany(companyId,startTime,endTime,appKey);
  }

  @Override
  public Map<String, Object> countFinishByNotCompay(
      Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countFinishByNotCompay(companyId,startTime,endTime,appKey);
  }

  @Override
  public Long countRunByNotCompany(Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countRunByNotCompany(companyId,startTime,endTime,appKey);
  }

  @Override
  public Long countCancelByCompany(Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countCancelByCompany(companyId,startTime,endTime,appKey);
  }

  @Override
  public Map<String, Object> countFinishByNotCompanyAndDriver(
      Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countFinishByNotCompanyAndDriver(companyId,startTime,endTime,appKey);
  }

  @Override
  public Long countRunByNotCompanyNotDriver(
      Long companyId, Date startTime, Date endTime, String appKey) {
    return orderMapper.countRunByNotCompanyNotDriver(companyId,startTime,endTime,appKey);
  }

  @Override
  public long countCancelAll(Date startTime, Date endTime, String appKey) {
    return orderMapper.countCancelAll(startTime,endTime,appKey);
  }

  @Override
  public Map<String, Object> countMain(Date startTime, Date endTime, String appKey) {
    return orderMapper.countMain(startTime,endTime,appKey);
  }

  @Override
  public long countByAppKey(Date startTime, Date endTime,String appKey) {
    return orderMapper.countByAppKey(startTime,endTime,appKey);
  }

  @Override
  public Long driverOrderDetailCount(OrderQuery orderQuery) {
    return orderMapper.driverOrderDetailCount(orderQuery);
  }

  @Override
  public List<Map<String, Object>> countOrderNumByDriver(Long[] driverIds, Date start, Date end, String appKey) {
    return orderMapper.countOrderNumByDriver(driverIds,start,end,appKey);
  }

  @Override
  public Map<String, Object> countOnDutyByDriver(Long driverId, Date start, Date end) {
    return orderMapper.countOnDutyByDriver(driverId,start,end);
  }

@Override
public List<Map<String, Object>> countBookDriver(Long zhuanYuyueMax,
		Date zhuanYuyueTime, String appKey) { 
	return orderMapper.countBookDriver(zhuanYuyueMax, zhuanYuyueTime, appKey);
}

@Override
public List<Map<String, Object>> countBusyBookDriver(Date zhuanYuyueTime,
		String appKey) {
	return orderMapper.countBusyBookDriver(zhuanYuyueTime, appKey);
}

@Override
public List<Map<String, Object>> findDriverBusy(Long zhuanYuyueMax,
		Date zhuanYuyueTime, String appKey, Long employId) {
	return orderMapper.findDriverBusy(zhuanYuyueMax, zhuanYuyueTime, appKey, employId);
}

@Override
public Integer getTodayBooks(Long employId, Date start, Date end) {
	return orderMapper.getTodayBooks(employId, start, end);
}
}
